﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class FrmTesting : Form
    {
        public FrmTesting()
        {
            InitializeComponent();
        }

        private void FrmTesting_Load(object sender, EventArgs e)
        {

        }

        private void rdoHappy_CheckedChanged(object sender, EventArgs e)
        {
            txtMood.Text = rdoHappy.Text;
        }

        private void rdoDepressed_CheckedChanged(object sender, EventArgs e)
        {
            txtMood.Text = rdoDepressed.Text;
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = "姓名：" + txtName.Text + "\n";
            //运用MessageBox的构造方法，对MessageBox的标题、图标MessageBoxIcon、按钮MessageBoxButtons进行设计。
            DialogResult result = MessageBox.Show(str, "请确认信息是否正确", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            if (result == DialogResult.OK)
            {
                txtName.Clear();
                chkReading.Checked = false;
                chkSport.Checked = false;
                rdoHappy.Checked = false;
                rdoDepressed.Checked = false;
            }
        }

        private void txtName_Validating(object sender, CancelEventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty)
            {
                MessageBox.Show("姓名不能为空！");
                txtName.Focus();
            }
        }

        private void txtInterest_TextChanged(object sender, EventArgs e)
        {
            
            
        }

        private void txtInterest_Validating(object sender, CancelEventArgs e)
        {
            String str = String.Empty;
            if (chkSport.Checked == true) str = "1";
            if (chkReading.Checked == true) str = "2";
            if (chkSport.Checked == true & chkReading.Checked == true) str = "3";
            switch (str)
            {
                case "1":
                    txtInterest.Text = txtName.Text + "喜欢" + chkSport.Text;
                    break;
                case "2":
                    txtInterest.Text = txtName.Text + "喜欢" + chkReading.Text;
                    break;
                case "3":
                    txtInterest.Text = txtName.Text + "喜欢" + chkSport.Text + "和" + chkReading.Text;
                    break;
                default:
                    txtInterest.Text = txtName.Text;
                    break;
            }
            //if (rdoDepressed.Checked == true)
            //{
            //    txtInterest.Text = txtName.Text + chkReading.Text;
            //}
            //else if (rdoHappy.Checked == true)
            //{
            //    txtInterest.Text = txtName.Text + chkSport.Text;
            //}
        }
    }
}
